A for in loop automatically includes the property of any prototype object, consider checking the key using hasOwnProperty.
When iterating over the keys of an object, this includes not only the keys of the
object, but also keys contained in the prototype of that object. It is generally
a best practice to check for these keys specifically:
varsomeObject;for(varkeyinsomeObject){if(!someObject.hasOwnProperty(key)){continue;// Skip keys from the prototype.}doSomethingWith(key);}
Loading history...
13
14
return lines;
15
}
16
17
/*
18
fileReadLines
19
Read a determined quantity of lines from a specific file
20
parameters
21
filePath (string) - file path to read lines from
22
lines (integer) - line quantity to read from file
23
startLine (integer) - line to start reading from
24
*/
25
function fileReadLines(filePath, lines = 2, startLine = 0) {
When iterating over the keys of an object, this includes not only the keys of the object, but also keys contained in the prototype of that object. It is generally a best practice to check for these keys specifically: